<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let number = 20
        let person = {
            sex: '男性',
            name: 'Daniel',
        }
        Object.defineProperty(person,'age',{
            // value: 18,
            // enumerable: true, // 对于新添加的属性的不可枚举性，默认是false
            // writable: true, // 属性的不可修改性，默认值是false
            // configurable: true,

            get: function() {
                console.log('有人读取age这个属性了')
                return number
            },
            set: function(value) {
                console.log('有人改变这个age值了');
                console.log('这是劫持的数据值', value);
                number = value
            }
        })

        console.log(person);
    </script>
</body>
</html>